package tests;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import tester.Example;
import tester.TestMethod;
import tester.Tester;
import tester.utilities.TesterUtility;

@Example
public class DataStructuresTests {

	@TestMethod
	public void testDataStructureCloneSucces(Tester t) {

		ArrayList<String> list = new ArrayList<String>();
		list.add("Foo");
		ArrayList<String> listCopy = TesterUtility.objectCopy(list);
		t.checkExpect(list, listCopy);

		HashMap<Integer, Integer> hash = new HashMap<Integer, Integer>();
		hash.put(5, 7);
		hash.put(4, 8);
		hash.put(2, 7);
		hash.put(1, 6);

		HashMap<Integer, Integer> hashClone = TesterUtility
				.objectCopy(hash);
		t.checkExpect(hash, hashClone);

		TreeSet<String> tree = new TreeSet<String>();
		tree.add("MyFoo");
		tree.add("MyZoo");
		tree.add("MyGoo");
		tree.add("Bar");

		TreeSet<String> treeClone = TesterUtility.objectCopy(tree);
		t.checkExpect(tree, treeClone);

		java.util.PriorityQueue<String> pq = new java.util.PriorityQueue<String>();
		pq.add("Foo");
		pq.add("MyBar");
		java.util.PriorityQueue<String> pqClone = TesterUtility
				.objectCopy(pq);
		t.checkExpect(pq, pqClone);

		TreeSet<Integer> ts = new TreeSet<Integer>();
		Random rand = new Random();
		for (int i = 0; i < 10; i++) {
			ts.add(rand.nextInt(100));
		}

		TreeSet<Integer> tsClone = TesterUtility.objectCopy(ts);
		t.checkExpect(tsClone, ts);

		TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
		tm.put(500, "Flee");
		tm.put(510, "Fleed");
		tm.put(520, "Flees");
		tm.put(530, "Fleef");
		tm.put(540, "Fleeg");
		tm.put(550, "Fleeh");

		TreeMap<Integer, String> tmClone = TesterUtility.objectCopy(tm);
		t.checkExpect(tmClone, tm);

		Stack<Integer> stack = new Stack<Integer>();
		stack.add(5);
		stack.add(6);
		stack.add(5);
		stack.add(6);
		stack.add(5);
		stack.add(6);
		stack.add(5);
		stack.add(6);

		Stack<Integer> stackClone = TesterUtility.objectCopy(stack);
		t.checkExpect(stack, stackClone);

	}

	public void cloneFailureTestsDataStructures(Tester t) {
		ArrayList<String> list = new ArrayList<String>();
		list.add("Foo");
		list.add("Bar");
		list.add("Me");
		ArrayList<String> listCopy = TesterUtility.objectCopy(list);
		list.add("FAIL FAIL FAIL!");
		t.checkExpect(list, listCopy);

		HashMap<Integer, Integer> hash = new HashMap<Integer, Integer>();
		hash.put(5, 7);
		hash.put(4, 8);
		hash.put(2, 7);
		hash.put(1, 6);

		// Works
		HashMap<Integer, Integer> hashClone = TesterUtility
				.objectCopy(hash);
		hash.put(99, 1000);
		t.checkExpect(hash, hashClone);

		TreeSet<String> tree = new TreeSet<String>();
		tree.add("MyFoo");
		tree.add("MyZoo");
		tree.add("MyGoo");
		tree.add("Bar");

		TreeSet<String> treeClone = TesterUtility.objectCopy(tree);
		tree.add("Big");
		tree.remove("MyFoo");
		t.checkExpect(tree, treeClone);

		java.util.PriorityQueue<String> pq = new java.util.PriorityQueue<String>();
		pq.add("Foo");
		pq.add("MyBar");
		java.util.PriorityQueue<String> pqClone = TesterUtility
				.objectCopy(pq);
		pq.add("ni");
		t.checkExpect(pq, pqClone);

		TreeSet<Integer> ts = new TreeSet<Integer>();
		Random rand = new Random();
		for (int i = 0; i < 10; i++) {
			ts.add(rand.nextInt(100));
		}

		TreeSet<Integer> tsClone = TesterUtility.objectCopy(ts);
		ts.add(12441);
		t.checkExpect(tsClone, ts);

		TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
		tm.put(500, "Flee");
		tm.put(510, "Fleed");
		tm.put(520, "Flees");
		tm.put(530, "Fleef");
		tm.put(540, "Fleeg");
		tm.put(550, "Fleeh");

		TreeMap<Integer, String> tmClone = TesterUtility.objectCopy(tm);
		tm.put(560, "BOING! FAIL FAIL FAIL");
		t.checkExpect(tmClone, tm);

		Stack<Integer> stack = new Stack<Integer>();
		stack.add(5);
		stack.add(6);
		stack.add(5);
		stack.add(6);
		stack.add(5);
		stack.add(6);
		stack.add(5);
		stack.add(6);

		Stack<Integer> stackClone = TesterUtility.objectCopy(stack);
		stack.add(1000);
		t.checkExpect(stack, stackClone);

	}
	
	public static void main(String[] args){
		Tester.runFullReport(new DataStructuresTests());
	}
}
